//加载公共样式
require('../../assets/css/public.less')

//加载自己的样式
require('./courseDetail.less')
// 服务器地址
const API = 'http://fitness.h5.itsource.cn:3701'

require('../../assets/public/fonts/iconfont.css')
// 请求axios工具
const request = require('../../lib/request/request')

window.onload = () => {
    // 获取id
    // console.log(location.search);
    let idd = location.search.split('=')[1]
    function fun() {
        request.get('/api/train/courseDetail', {
            params: {
                id: idd,
            }
        }).then((res) => {
            console.log(res.data);
            let { errno, data } = res.data
            //判断
            if (errno === 0) {
                //把训练数据存储到本地 给play页面用
                localStorage.setItem('fragments', JSON.stringify(data.fragments))
                word1.textContent = data.name
                num.textContent = data.calorie
                clock.textContent = data.time
                numPerson.textContent = data.peoplenum
                content.textContent = data.desc
                week.textContent = data.frequency
                machine.textContent = data.instrument
            }
        })
        let frame = JSON.parse(localStorage.getItem('fragments'))
        // console.log(frame[1].videoUrl);
        if (idd < 3) {
            player.src = API + frame[idd].videoUrl
        } else {
            idd = 2
            player.src = API + frame[idd].videoUrl
        }
        request.get('/api/user/info').then(res => {
            let { errno, data } = res.data
            if (errno === 0) {
                console.log('res.data :>> ', res.data);
                img.src = API + data.imgUrl
                userNmae.textContent = data.nickName
                intor.textContent = data.sign
            }
        })
    }
    fun()
}

